/**
 * @Title: SignController
 * @Package cn.com.yiqi.wsc.api.controller
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-林威
 * @date 2017/2/17 16:36
 * @version V1.0
 */
package cn.com.yiqi.wsc.api.controller;
import cn.com.yiqi.wsc.Ro.ItemInfoVO;
import cn.com.yiqi.wsc.api.common.Setting;
import cn.com.yiqi.wsc.api.common.SettingUtils;
import cn.com.yiqi.wsc.api.controller.ro.CommonRO;
import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultUtil;
import cn.com.yiqi.wsc.entity.customer.Customer;
import cn.com.yiqi.wsc.service.customer.CustomerService;
import cn.com.yiqi.wsc.service.customer.impl.CustomerImpl;
import cn.com.yiqi.wsc.service.customer.impl.SignserviceImpl;
import cn.com.yiqi.wsc.service.item.ItemService;
import cn.com.yiqi.wsc.service.item.enumerate.ItemKindEnum;
import cn.com.yiqi.wsc.service.item.impl.ItemServiceImpl;
import cn.com.yiqi.wsc.service.point.PointService;
import cn.com.yiqi.wsc.service.point.dataobject.PointInfoDO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 *
 *@ClassName: SignController
 * Description: TODO
 * @author 会员系统组-林威
 * @date 2017/2/17 16:36
 *
 */
@ResponseBody
@Controller
@RequestMapping("/api/sign")
public class ApiSignController {

    @Autowired
    SignserviceImpl signservice;

    @Autowired
    PointService pointService;

    @Autowired
    CustomerService customerService;

    @Autowired
    ItemServiceImpl itemService;

    @RequestMapping("/detail")
    public Result signDetailMoth(@RequestBody CommonRO ro){

        Result<Customer> re = customerService.isExist(ro.getUserId());
        if(!ResultUtil.isSuccess(re)){
            return re;
        }
        Integer signDays = signservice.getContinuitySign(ro.getUserId());
        Calendar cal_1=Calendar.getInstance();//获取当前日期
        cal_1.add(Calendar.MONTH, -1);
        cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
        Date firstDay = cal_1.getTime();
        //TODO 获取本月签到详情
        List<String> signDetail = signservice.getSignDetail(ro.getUserId(),firstDay,new Date());

        Integer point = re.getReturnValue().getPoint();
        re.putData("signDays",signDays);
        re.putData("detail",signDetail);
        re.putData("point",point);
        return re;
    }

    @RequestMapping("/sign")
    public Result sign(@RequestBody CommonRO ro){
        return signservice.sign(ro.getUserId());
    }

    @RequestMapping("/pointItem")
    public Result pointItem(@RequestBody CommonRO ro){
        Result re = new Result();
        if(null == ro.getPageSize()){
            ro.setPageSize(10);
            ro.setCurrentPage(1);
        }
        PageInfo<ItemInfoVO> page =  itemService.finditemInfo(null,ro.getPageSize(),ro.getCurrentPage(), ItemKindEnum.point.getValue());
        re.putData("page",page);
        return re;
    }
}
